<template>
  <div class="real-population-wrapper">
    <ThirdMenu :thirdRotues="routes" :title="title"></ThirdMenu>
    <router-view :key="timeStamp"></router-view>
  </div>
</template>

<script>
import ThirdMenu from '@/components/thirdMenu/ThirdMenu'
import Bus from '@/utils/Bus'
export default {
  name: 'RealPopulation',
  data () {
    return {
      title: '实有人口',
      timeStamp: ''
    }
  },
  computed: {
    routes () {
      let secondRoutes = this.$router.options.routes.filter((item) => {
        return item.name === this.$route.matched[0].name
      })[0].children

      if (!secondRoutes) {
        secondRoutes = []
      }

      let thirdRoutes = secondRoutes.filter((item) => {
        return item.name === this.$route.matched[1].name
      })[0].children

      if (!thirdRoutes) {
        thirdRoutes = []
      }

      return thirdRoutes.map((item) => {
        item.totalPath = `${this.$route.matched[1].path}/${item.path}`
        return item
      })
    }
  },
  components: {
    ThirdMenu
  },
  beforeMount () {
    // 在当前路由组件下刷新当前路由组件
    Bus.$on(this.CNST.UPDATE_TIME_STAMP, () => {
      this.timeStamp = new Date().getTime()
    })
  },
  beforeDestroy () {
    Bus.$off(this.CNST.UPDATE_TIME_STAMP)
  }
}
</script>

<style lang="scss" scoped>
</style>
